package com.wolf.controller;

import com.wolf.pojo.Wl_user_role;
import com.wolf.service.Wl_user_roleService;
import com.wolf.util.Math;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@Controller
@ComponentScan
public class Wl_user_roleController {

    @Autowired
    private Wl_user_roleService wl_user_roleService;

    public void setWl_user_roleService(Wl_user_roleService wl_user_roleService) {
        this.wl_user_roleService = wl_user_roleService;
    }

    /**
     * 查询所有
     * @param modelMap
     * @return
     */
    @RequestMapping("wl_user_rolegetall")
    public String getAll(ModelMap modelMap){

        List<Wl_user_role> list = wl_user_roleService.getAll();

        modelMap.addAttribute("wl_user_rolelist",list);

        return "table_wl_user_role";
    }

    /**
     * 模糊查询
     * @param rolename
     * @param rolecode
     * @return
     */
    @RequestMapping("getselective")
    public String getSelective(ModelMap model,String rolename, String rolecode){

        model.addAttribute("wl_user_rolelist",wl_user_roleService.getSelective(rolename,rolecode));

        return "table_wl_user_role";
    }

    /**
     * 新增
     * @param rolename
     * @param rolecode
     * @return
     */
    @RequestMapping("wl_user_role_insert")
    @ResponseBody
    public int wl_user_role_insert(String rolename,String rolecode){

        Wl_user_role wl = new Wl_user_role();
        wl.setId(Math.random());
        wl.setRolename(rolename);
        wl.setRolecode(rolecode);
        return wl_user_roleService.insert(wl);
    }

    /**
     * 删除
     * @param id
     * @return
     */
    @RequestMapping("wl_user_role_delete")
    public String wl_user_role_delete(String id){

        wl_user_roleService.deleteByPrimaryKey(id);

        return "redirect:wl_user_rolegetall";
    }

    /**
     * 查询单个对象
     * @param id
     * @return
     */
    @RequestMapping("wl_user_role_getbyid")
    @ResponseBody
    public Wl_user_role wl_user_role_getbyid(String id){

        return wl_user_roleService.selectByPrimaryKey(id);
    }

    /**
     * 修改
     * @param id
     * @param rolename
     * @param rolecode
     * @return
     */
    @RequestMapping("wl_user_role_update")
    @ResponseBody
    public int wl_user_role_update(String id,String rolename,String rolecode){

        Wl_user_role wl_user_role = new Wl_user_role();
        wl_user_role.setId(id);
        wl_user_role.setRolename(rolename);
        wl_user_role.setRolecode(rolecode);

        return wl_user_roleService.updateByPrimaryKey(wl_user_role);
    }

}
